﻿<?php
require_once "db.class.php";
require_once "config.php";
require_once "OpenApiV3.php";

$openid = $_POST['openid'];
$openkey = $_POST['openkey'];
$pf = $_POST['pf'];
$pfkey = $_POST['pfkey'];
$ts = time();
$payitem = $_POST['payitem'];
$goodsmeta = $_POST['goodsmeta'];
$goodsurl = $_POST['goodsurl'];

$sdk = new OpenApiV3($appid, $appkey);
$sdk->setServerName($server_name);
		
$params = array(
	'openid' => $openid,
	'openkey' => $openkey,
	'pf' => $pf,
	'pfkey' => $pfkey,
	'ts' => $ts,
	'payitem' => $payitem,
	'goodsmeta' => $goodsmeta,
	'goodsurl' => $goodsurl,
);

$script_name = '/v3/pay/buy_goods';

$qqRet = $sdk->api($script_name, $params, 'post', 'https');
//如果返回正确
if ($qqRet['ret'] == 0)
{
	$params = array("host"=>"$host", "user"=>"$user", "pass"=>"$pass", "db"=>"$db");
	$db = new Dbclass($params, false);

	//插入新token
	$sql = "insert into ".$tb_order_profile." (openId, token, payitem) values ('".$openid."', '".$qqRet['token']."', '".$payitem."')";
	$result = $db->query($sql);

	$db->close();

	echo $qqRet['url_params'];
}

?>
